package q1684_countConsistentStrings;

public class Solution {
    /*
    统计一致字符串的数目
    位运算的方式解决该问题
     */
    public int countConsistentStrings(String allowed, String[] words) {
        int mask = 0, ans = 0;
        for (int i = 0; i < allowed.length(); i++) mask |= 1 << (allowed.charAt(i) - 'a');

        for (String word : words) {
            int cnt = 0;
            for (int i = 0; i < word.length(); i++) cnt |= 1 << (word.charAt(i) - 'a');
            ans += (cnt | mask) == mask ? 1 : 0;
        }
        return ans;
    }
}
